using System;
using System.Collections.Generic;
using System.Configuration.Provider;
using System.Text;
using BlogEngine.Core.Provider.Interfaces;

namespace BlogEngine.Core.Provider
{
	public class BlogProviderBase : ProviderBase
	{
		static private Dictionary<Type, object> _interfaces = new Dictionary<Type, object>();

		/// <summary>
		/// Registers the specified type.
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="o">The object.</param>
		static public void Register(Type type, object o)
		{
			if (!_interfaces.ContainsKey(type))
				_interfaces.Add(type, o);
		}

		/// <summary>
		/// Gets the interface.
		/// </summary>
		/// <returns></returns>
		public T GetInterface<T>()
		{
			Object o;

			if (_interfaces.TryGetValue(typeof(T), out o))
				return (T)o;

			if (!(o is T))
				throw new Exception("Unknown interface type returned.");

			throw new Exception("Unknown interface requested.");
		}

	}
}
